<?php
class classBasketService{
    private $iIndex=0;
    private $basket_sess_name = 'ShopBasket';
    
    
    public function iCount(){
        $_basket_sess = new classSessions();
        $_basket_sess_str = $_basket_sess->open($this->basket_sess_name);

        //////////////////////////////////
        if(_DBG_MODE_=='YES') file_put_contents('plugins/order/results/4.txt', '$_basket_sess_str -> '.$_basket_sess_str.' session name-> '.$this->basket_sess_name);
        //////////////////////////////////
        
        if(trim($_basket_sess_str)!='')
          return Count(explode('/',$_basket_sess_str));
        else
          return 0;
    }
    
    public function aGetFirst(){
        if($this->iCount()>0){
            $_basket_sess     = new classSessions();
            $_basket_sess_str = $_basket_sess->open($this->basket_sess_name);
            $_basket_array    = explode('/',$_basket_sess_str);
            $this->iIndex     = 0;
            
            $basket_record_array = explode(';',$_basket_array[0]);            
            $result_array['ProductID']    = $basket_record_array[0];
            $result_array['ProductCount'] = $basket_record_array[1];
            $result_array['ProductDetail']= $basket_record_array[2];
            
            return $result_array;
        }
        return false;
    }
    
    public function aGetNext(){
        $iCount = $this->iCount();
        if(($iCount>0) and ($this->iIndex >=0) and ($this->iIndex+1 < $iCount)){
            $_basket_sess     = new classSessions();
            $_basket_sess_str = $_basket_sess->open($this->basket_sess_name);
            $_basket_array    = explode('/',$_basket_sess_str);
            $this->iIndex++;
            
            $basket_record_array = explode(';',$_basket_array[$this->iIndex]);            
            $result_array['ProductID']    = $basket_record_array[0];
            $result_array['ProductCount'] = $basket_record_array[1];
            $result_array['ProductDetail']= $basket_record_array[2];
            
            return $result_array;
        }
        return false;
    }
}
?>
